package com.demo.expertsystemdemo.controller;

import com.demo.expertsystemdemo.entity.dto.MqttSenderDTO;
import com.demo.expertsystemdemo.mqtt.mqtt.MqttSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lzb22
 */
@RestController
@RequestMapping("/mqtt")
public class MqttSenderController {
    private final MqttSender mqttSender;
    public MqttSenderController(MqttSender mqttSender) {
        this.mqttSender = mqttSender;
    }
    @PostMapping(value = "/send")
    public void sendToMqtt(@RequestBody MqttSenderDTO dto) {
        mqttSender.sendToMqtt(dto.getTopic(), dto.getMessage());
    }
    @GetMapping(value = "/getConfigMQ/{sn}")
    public void getConfigMq(@PathVariable String sn) {
        String message = "{\"report\":\"true\"}";
        mqttSender.sendToMqtt("Config_req/" + sn,message);
    }

    @GetMapping(value = "/getModelMQ/{sn}")
    public void getModelMq(@PathVariable String sn) {
        String message = "{\"report\":\"true\"}";
        mqttSender.sendToMqtt("Model_req/" + sn,message);
    }
}
